<?php
session_start();
require '../nette/Nette/loader.php';
require '../db.php';
require '../localization/lang.php';
require '../core/core.sanitizer.php';
require '../core/core.security.php';
require '../core/core.dfs.php';
require '../visual/visual.dfs.php';
require '../core/core.time.php';
require '../core/core.statistics.php';

$login=new core_security;
if ($login->checklogin()=="OK" AND $_SESSION['role']<=2) {
$loc=new loc;
$datetime=new core_time;
$datefrom=explode("/",$_POST['datefrom']);
$datetime->date=$datefrom[1].":".$datefrom[0].":".$datefrom[2];
$datetime->time="00:01";
//$from=$datetime->totimestamp();
$from=strtotime($_POST['datefrom']." 00:00:01");
$dayfrom=strtotime($_POST['datefrom']);
$dateto=explode("/",$_POST['dateto']);
$dayto=strtotime($_POST['dateto']);
$datetime->date=$dateto[1].":".$dateto[0].":".$dateto[2];
$datetime->time="23:59";
//$to=$datetime->totimestamp();
$to=strtotime($_POST['dateto']." 23:59:59");
$statist=new core_statistics($_POST['datefrom'],$_POST['dateto']);



$users="";
$query="select * from users WHERE disabled != 1";
$result=mysql_query($query);
if ($_POST['datefrom'] != "" AND $_POST['dateto'] != "") {
echo "<b>".$loc->attendancefor.$_POST['datefrom']." - ".$_POST['dateto']."</b><br>";
echo "<div class='maindiv'id='attendanceshow'><table>";
echo "<tr ><th class='statsheader'>".$loc->user."</th><th class='statsheader'>".$loc->attendancefromattendance."</th><th class='statsheader'>".$loc->attendancefromworkload."</th></tr>";
while ($row=mysql_fetch_array($result)) {
	$query2="select sum(att) as attend from attendance where day >= ".$dayfrom." AND day <= ".$dayto." AND uid = ".$row['id']."";
	$statist->uid=$row['id'];
	$result2=mysql_query($query2);
	$row2=mysql_fetch_array($result2);
	$attendfromwork=$statist->return_total();
	if ($attendfromwork=="") {$attendfromwork=0;}
	if ($row2['attend']== $attendfromwork) { $trclass="statsok";} else { $trclass="statsfail";}
	echo "<tr class='".$trclass."' onClick='attend_details(\"".$row['id']."\",\"".$_POST['datefrom']."\",\"".$_POST['dateto']."\");'><td class='stats'>".$row['name']."</td><td class='stats'>".$datetime->tohm($row2['attend'])."</td><td>".$datetime->tohm($attendfromwork)."</td></tr>";
	}


}
echo "</table></div>";
}
?>
